﻿using API;
using API.Store;
using Common;
using DevExpress.Xpo;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BLL
{
    public class EmployeeBLL
    {
        public void BatchInsert()
        {
            try
            {
                ApiStore dataProxy = ServiceProxy.ApiStoreProxy();
                MB_Employee[] employees = dataProxy.GetEmployees(null);
                if (employees == null || employees.Length <= 0) return;
                using (UnitOfWork uow = DatabaseSchema.UnitOfWork)
                {
                    foreach (MB_Employee e in employees)
                    {
                        B_Employee employee = new B_Employee(uow);
                        employee.EmployeeID = e.EmployeeID;
                        employee.Name = e.Name;
                        employee.Sex = e.Sex;
                        employee.IDCard = e.IDCard;
                        employee.Phone = e.Phone;
                        employee.StatusID =e.StatusID;
                        employee.Sort = e.Sort;
                        employee.Creator = e.Creator;
                        employee.CreateDT = e.CreateDT;
                        employee.Operator = e.Operator;
                        employee.UpdateDT = e.UpdateDT.Value;
                        employee.Remark = e.Remark;
                        employee.Save();
                    }
                    uow.CommitChanges();
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorLog("EmployeeBLL.BatchInsert", ex);
            }
        }
    }
}
